home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlib.zip / CTYPES.H < prev    next >
Text File  |  1993-01-04  |  2KB  |  48 lines

  1.  
  2. /*  File   : ctypes.h
  3.     Author : Richard A. O'Keefe.
  4.     Updated: 26 April 1984
  5.     Purpose: Reimplement the UNIX ctype(3) library.
  6.  
  7.     isaneol(c) means that c is a line terminating character.
  8.     isalnum, ispunct, isspace, and isaneol are defined on the
  9.     range -1..127, i.e. on ASCII U {EOF}, while all the other
  10.     macros are defined for any integer.
  11.  
  12.     isodigit(c) checks for Octal digits.
  13.     isxdigit(c) checkx for heXadecimal digits.
  14. */
  15.  
  16. #define isdigit(c)      ((unsigned)((c)-'0') < 10)
  17. #define islower(c)      ((unsigned)((c)-'a') < 26)
  18. #define isupper(c)      ((unsigned)((c)-'A') < 26)
  19. #define isprint(c)      ((unsigned)((c)-' ') < 95)
  20. #define iscntrl(c)      ((unsigned)((c)-' ') >= 95)
  21. #define isascii(c)      ((unsigned)(c) < 128)
  22. #define isalpha(c)      ((unsigned)(((c)|32)-'a') < 26)
  23.  
  24. extern  char    _c2type[];
  25.  
  26. #define isalnum(c)      (_c2type[(c)+1] < 36)
  27. #define ispunct(c)      (_c2type[(c)+1] == 36)
  28. #define isspace(c)      (_c2type[(c)+1] > 37)
  29. #define isaneol(c)      (_c2type[(c)+1] > 38)
  30.  
  31. #define isxdigit(c)     (_c2type[(c)+1] < 16)
  32. #define isodigit(c)     ((unsigned)((c)-'0') < 8)
  33.  
  34. /*  The following "conversion" macros have been in some versions of UNIX
  35.     but are not in all.  tocntrl is new.  The original motivation for ^?
  36.     being a name for DEL was that (x)^64 mapped A..Z to ^A..^Z and also
  37.     ? to DEL.  The trouble is that this trick doesn't work for lower case
  38.     letters.  The version given here is not mine.  I wish it was.  It has
  39.     the nice property that DEL is mapped to itself (so does EOF).
  40.     tolower(c) and toupper(c) are only defined when isalpha(c).
  41. */
  42. #define tolower(c)      ((c)|32)
  43. #define toupper(c)      ((c)&~32)
  44. #define tocntrl(c)      (((((c)+1)&~96)-1)&127)
  45. #define toascii(c)      ((c)&127)
  46.  
  47.  
  48.